<?php 
function quicksort($mang,$trai,$phai){
	
}

if(!isset($_SESSION)) 
{ 
	session_start(); 
}
if(isset($_REQUEST['ten'])){
	include 'sorclass.php';
	$ten=$_REQUEST['ten'];
	//$mht=array();
	if('carnumber'==$ten){
		//$mht=array_reverse($_SESSION['mrs']);
		//$_SESSION['mrs']=$mht;
		$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		$sl=count($_SESSION['mrs']);
		if($sl>0){
			
			?>
			<table border="1">
				<tr>
					<td style="cursor: pointer" onclick="sordiem('id')">id</td>
					<td style="cursor: pointer" onclick="sordiem('name')">name</td>
					<td style="cursor: pointer" onclick="sordiem('datetime')">datetime</td>
					<td style="cursor: pointer" onclick="sordiem('carnumber')">carnum</td>
					<td>filename</td>
					<td>host</td>
					<td>reg</td>
				</tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){	
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mrs'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mrs'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
					
				}
				?>
			</table>
			<?php 		
		}
	}else if('datetime'==$ten){
		if(isset($_SESSION['mdatetime'])){
			$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		}else{
			$_SESSION['mdatetime']=array();
			$mt=array();
			$tem=$_SESSION['mrs'];
			foreach($_SESSION['mrs'] as $key=>$gt){
				 $obja=unserialize (serialize($_SESSION['mrs'][$key]));
				 $mt[]=$obja->datetime;
			}
			array_unique ($mt);
			sort($mt);
			$soluong=count($mt);
			if($soluong>0){
				for($i=0;$i<$soluong;$i++){
					foreach($tem as $k=>$vl){
						$oj=unserialize (serialize($tem[$k]));
						if($oj->datetime==$mt[$i]){
							$_SESSION['mdatetime'][]=$oj;
							unset( $tem[$k] );
						}
					}
				}
			}
		}
		$sl=count($_SESSION['mdatetime']);
		echo "a:".$sl;
		if($sl>0){
			?>
			<table border="1">
				<tr>
					<td style="cursor: pointer" onclick="sordiem('id')">id</td>
					<td style="cursor: pointer" onclick="sordiem('name')">name</td>
					<td style="cursor: pointer" onclick="sordiem('datetime')">datetime</td>
					<td style="cursor: pointer" onclick="sordiem('carnumber')">carnum</td>
					<td>filename</td>
					<td>host</td>
					<td>reg</td>
				</tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){	
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mdatetime'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mdatetime'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
					
				}
				?>
			</table>
			<?php
		}
	}else if('name'==$ten){
		if(isset($_SESSION['mname'])){
			$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		}else{
			$_SESSION['mname']=array();
			$mt=array();
			$tem=$_SESSION['mrs'];
			foreach($_SESSION['mrs'] as $key=>$gt){
				 $obja=unserialize (serialize($_SESSION['mrs'][$key]));
				 $mt[]=$obja->name;
			}
			array_unique ($mt);
			sort($mt);
			$soluong=count($mt);
			if($soluong>0){
				for($i=0;$i<$soluong;$i++){
					foreach($tem as $k=>$vl){
						$oj=unserialize (serialize($tem[$k]));
						if($oj->name==$mt[$i]){
							$_SESSION['mname'][]=$oj;
							unset( $tem[$k] );
						}
					}
				}
			}
		}
		$sl=count($_SESSION['mname']);
		echo "a:".$sl;
		if($sl>0){
			?>
			<table border="1">
				<tr>
					<td style="cursor: pointer" onclick="sordiem('id')">id</td>
					<td style="cursor: pointer" onclick="sordiem('name')">name</td>
					<td style="cursor: pointer" onclick="sordiem('datetime')">datetime</td>
					<td style="cursor: pointer" onclick="sordiem('carnumber')">carnum</td>
					<td>filename</td>
					<td>host</td>
					<td>reg</td>
				</tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){	
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mname'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mname'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
					
				}
				?>
			</table>
			<?php
		}
	}else if('id'==$ten){
		if(isset($_SESSION['mid'])){
			$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		}else{
			$_SESSION['mid']=array();
			$mt=array();
			$tem=$_SESSION['mrs'];
			foreach($_SESSION['mrs'] as $key=>$gt){
				 $obja=unserialize (serialize($_SESSION['mrs'][$key]));
				 $mt[]=$obja->id;
			}
			array_unique ($mt);
			sort($mt);
			$soluong=count($mt);
			if($soluong>0){
				for($i=0;$i<$soluong;$i++){
					foreach($tem as $k=>$vl){
						$oj=unserialize (serialize($tem[$k]));
						if($oj->id==$mt[$i]){
							$_SESSION['mid'][]=$oj;
							unset( $tem[$k] );
						}
					}
				}
			}
		}
		$sl=count($_SESSION['mid']);
		if($sl>0){
			?>
			<table border="1">
				<tr>
					<td style="cursor: pointer" onclick="sordiem('id')">id</td>
					<td style="cursor: pointer" onclick="sordiem('name')">name</td>
					<td style="cursor: pointer" onclick="sordiem('datetime')">datetime</td>
					<td style="cursor: pointer" onclick="sordiem('carnumber')">carnum</td>
					<td>filename</td>
					<td>host</td>
					<td>reg</td>
				</tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){	
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mid'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mid'][$i]));
						?>
						<tr>
							<td><?=$obj->id ?></td>
							<td><?=$obj->name ?></td>
							<td><?=$obj->datetime ?></td>
							<td><?=$obj->carnum ?></td>
							<td><?=$obj->filename ?></td>
							<td><?=$obj->host ?></td>
							<td><?=$obj->reg ?></td>						
						</tr>
						<?php 
					}
					
				}
				?>
			</table>
			<?php
		}
	}
	
	
	
}
?>